package br.com.adimoveis.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import br.com.adimoveis.ui.ICrudTableModel;

public class ClienteTableModel extends AbstractTableModel implements ICrudTableModel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<Cliente> clientes;
	
	private String[] colunas = {"Nome","Telefone 1","Telefone 1","Celular","E-Mail"};
	
	public ClienteTableModel(Cliente[] imoveis){
		setItems(imoveis);
	}
	
	@SuppressWarnings("unchecked")
	public void setItems(Object[] imoveis) {
		this.clientes = new ArrayList<Cliente>();
		this.clientes.addAll((Collection<? extends Cliente>) Arrays.asList(imoveis));
		fireTableDataChanged();
	}
	
	
	public int getColumnCount() {
		return colunas.length;
	}

	
	public int getRowCount() {
		return clientes.size();
	}
	
	
	public String getColumnName(int column) {
		return colunas[column];
	}

	
	public Object getValueAt(int rowIndex, int columnIndex) {
		Cliente cliente = clientes.get(rowIndex);
		if(columnIndex == 0){
			return cliente;
		}else if(columnIndex == 1){
			return cliente.getTelefone1();
		}else if(columnIndex == 2){
			return cliente.getTelefone2();
		}else if(columnIndex == 3){
			return cliente.getCelular();
		}else if(columnIndex == 4){
			return cliente.getEmail();
		}
		return "";
	}
	
	
	
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}

	public Cliente getClienteAt(int index) {
		if(index >= 0){
			return clientes.get(index);
		}else{
			return null;
		}
	}

}
